<template>
  <div class="masonry-view">
    <ul v-masonry transition-duration="1s" item-selector=".item">
      <li
        v-masonry-tile
        class="item"
        v-for="(r, i) in DataArr"
        :key="i"
        v-lazy="r.postData.postView.firstImage.orign"
        @click="goToHomeItem(r.itemId)"
      >
        <i class="play" v-if="video"></i>
        <div class="img" v-if="r.postData">
          <img :src="r.postData.postView.firstImage.orign" />
          <span class="photo-count" v-if="r.postData">{{r.postData.postView.photoCount}}</span>
        </div>

        <div
          class="text"
          :class="[r.postData.postView.type==1 ? 'article' : '' ]"
          v-if="r.postData"
        >
          <div class="van-multi-ellipsis--l2" v-if="r.postData" v-html="r.postData.postView.digest"></div>
          <i></i>
        </div>

        <div class="tag">
          <span v-if="r.postData">#{{r.postData.postView.tagList[0]}}</span>
        </div>

        <div class="bottom">
          <div class="user">
            <img :src="r.blogInfo.bigAvaImg" />
            <div class="van-ellipsis">{{r.blogInfo.blogNickName}}</div>
          </div>
          <div class="favorite">
            <i
              :class="[r.postData.postCount.viewCount == 1 ? 'selected' : '']"
              @click.stop="switchSelected(r.itemId,r.postData.postView.firstImage.orign)"
            ></i>
            <span>{{r.postData.postCount.favoriteCount}}</span>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: "MasonryView",
  props: ["DataArr", "video", "switchSelected"],
  methods: {
    goToHomeItem(id) {
      // this.$router.go(0);
      // console.log("MasonryView" + id);
      // console.log("MasonryView router" + this.$route.params.id);
      this.$router.push({
        name: "item",
        params: {
          id
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.masonry-view {
  ul {
    min-height: 100vh;
    display: flex;
    flex-flow: row wrap;
    justify-content: space-between;
    align-items: flex-start;
    li {
      width: 50%;
      padding: 5px;
      margin: 10px 0;
      position: relative;

      .play {
        width: 50px;
        height: 50px;
        display: block;
        background-image: url("~@/assets/images/home/_0o.png");
        background-repeat: no-repeat;
        background-position: center center;
        background-size: contain;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 50;
      }

      .img {
        width: 100%;
        position: relative;
        img {
          display: block;
          width: 100%;
          border: 1px solid #f2f2f2;
          border-radius: 10px;
        }

        .photo-count {
          width: 20px;
          height: 20px;
          line-height: 20px;
          font-size: 14px;
          padding: 2px;
          text-align: center;
          color: rgb(255, 255, 255);
          background-color: rgba(0, 0, 0, 0.5);
          border-radius: 999px;
          position: absolute;
          right: 10px;
          bottom: 10px;
        }
      }

      .text {
        height: 32px;
        display: flex;
        margin: 10px 0 0 0;
        justify-content: space-between;

        div {
          width: 95%;
          font-size: 16px !important;
          overflow: hidden;

          p {
            background-color: rgb(255, 0, 0);
          }
        }

        i {
          width: 20px;
          height: 20px;
          display: block;
          background-image: url("~@/assets/images/home/0Yh.png");
          background-repeat: no-repeat;
          background-position: center center;
          background-size: contain;
        }
      }

      .article {
        min-height: 100px;
        max-height: 350px;
        position: relative;
        div {
          border-radius: 10px;
          background-color: #f5f5f5;
          overflow: hidden;
        }

        i {
          position: absolute;
          bottom: -28px;
          right: 10px;
        }
      }

      .tag {
        margin: 10px 0;
        span {
          padding: 3px 6px;
          font-size: 12px;
          color: #bfbfbf;
          border-radius: 10px;
          background-color: #f5f5f5;
        }
      }

      .bottom {
        margin-top: 5px;
        display: flex;
        justify-content: space-between;

        .user {
          display: flex;
          align-items: center;
          img {
            width: 20px;
            height: 20px;
            border-radius: 999px;
            margin-right: 3px;
          }

          div {
            width: 100px;
            font-size: 12px;
            color: #bfbfbf;
          }
        }

        .favorite {
          display: flex;
          align-items: center;
          i {
            width: 20px;
            height: 20px;
            display: block;
            background-image: url("~@/assets/images/home/2uA.png");
            background-repeat: no-repeat;
            background-position: center center;
            background-size: contain;
            margin-right: 3px;
          }

          .selected {
            background-image: url("~@/assets/images/home/5vM.png");
          }
          span {
            font-size: 12px;
            color: #bfbfbf;
          }
        }
      }
    }
  }
}
</style>